package handler

import (
	"encoding/json"
	"github.com/gin-gonic/gin"
	"post-hub/inits"
	"post-hub/internal/dto"
	"post-hub/internal/model"
	"post-hub/response"
	"strconv"
	"time"
)

func ShowPost(c *gin.Context) {

	var post model.Post
	err := c.ShouldBind(&post)
	if err != nil {
		response.Error(c, "解析失败")
		return
	}
	err = dto.ShowPost(&post, int(post.ID))
	if err != nil {
		response.Error(c, "查询失败")
		return
	}
	response.Success(c, "查询成功", post)
	postKey := "post" + strconv.Itoa(int(post.ID))
	marshal, err := json.Marshal(&post)
	if err != nil {
		response.Error(c, "转化失败")
		return
	}
	inits.Rdb.Set(inits.Ctx, postKey, marshal, time.Minute*5)
}
